package com.yileiqian.alg;

public class OneProblem {
	public static int oneProblem(int n) {
		int count = 0;
		int factor = 1;

		int lowerNum = 0;
		int currNum = 0;
		int higherNum = 0;

		while (n / factor != 0) {
			lowerNum = n - n / factor * factor;
			currNum = n / factor % 10;
			higherNum = n / (factor * 10);

			if (currNum == 0) {
				count += higherNum * factor;
			} else if (currNum == 1) {
				count += higherNum * factor + lowerNum + 1;
			} else {
				count += (higherNum + 1) * factor;
			}

			factor *= 10;
		}

		return count;
	}
}
